package com.mo.lib.utils.anim

import android.animation.ObjectAnimator
import android.view.View
import android.view.animation.*

/**
 * @ author：mo
 * @ data：2022/7/18:15:53
 * @ 功能：
 * 差值器：LinearInterpolator=其变化速率恒定  AccelerateInterpolator=其变化开始速率较慢，后面加速    DecelerateInterpolator=其变化开始速率较快，后面减速
 *
 */

/** 动画类别：旋转=rotation、rotationX、rotationY          values可变参数：第一个参数=动画起始位置或样式    最后一个参数=动画结束位置或样式，其他=动画执行节点*/
fun View.objectAnimator(propertyName: String, vararg values: Float) = ObjectAnimator.ofFloat(this, propertyName, *values)
fun View.objectAnimatorRotationZ(vararg values: Float) = objectAnimator(propertyName = "rotation", *values)
fun View.objectAnimatorRotationX(vararg values: Float) = objectAnimator(propertyName = "rotationX", *values)
fun View.objectAnimatorRotationY(vararg values: Float) = objectAnimator(propertyName = "rotationY", *values)

fun View.objectAnimatorTranslationX(vararg values: Float) = objectAnimator(propertyName = "translationX", *values)
fun View.objectAnimatorTranslationY(vararg values: Float) = objectAnimator(propertyName = "translationY", *values)

fun View.objectAnimatorScaleX(vararg values: Float) = objectAnimator(propertyName = "scaleX", *values)
fun View.objectAnimatorScaleY(vararg values: Float) = objectAnimator(propertyName = "scaleY", *values)

fun View.objectAnimatorAlpha(vararg values: Float) = objectAnimator(propertyName = "alpha", *values)

/** 设置动画时长*/
fun Animation.setDurations(duration: Long): Animation {
    this.duration = duration
    return this
}

/** 设置动画监听*/
fun Animation.setListener(animationListener: Animation.AnimationListener): Animation {
    this.setAnimationListener(animationListener)
    return this
}


/** 自身为基点，从自身的底部为起点移动到正常位置*/
fun getTranslateAnimationBottom2Self() = TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f)

/** 以自身为基点，从自身的顶点为起点移动到正常位置*/
fun getTranslateAnimationTop2Self() = TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f)

/**以自身为基点，从自身的左侧为起点移动到正常位置 */
fun getTranslateAnimationSelf2Left() = TranslateAnimation(Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f)

/**以自身为基点，从自身的右侧为起点移动到正常位置 */
fun getTranslateAnimationSelf2Right() = TranslateAnimation(Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f)

/**以自身为基点，从自身左上角为起点放大指定倍数 */
fun getScaleAnimationAnimationBig(multiple: Float) = ScaleAnimation(0.0f, multiple, 0.0f, multiple, ScaleAnimation.RELATIVE_TO_SELF.toFloat(), ScaleAnimation.RELATIVE_TO_SELF.toFloat())

/**以自身为基点，从自身左上角为起点缩小指定倍数 */
fun getScaleAnimationAnimationSmall(multiple: Float) = ScaleAnimation(multiple, 0.0f, multiple, 0.0f, ScaleAnimation.RELATIVE_TO_SELF.toFloat(), ScaleAnimation.RELATIVE_TO_SELF.toFloat())

/**以自身为基点，旋转一圈 */
fun getRotateAnimationAnimationAnimationSelf() = RotateAnimation(0f, 359f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)

/**透明度变化：fromAlpha=初始透明度（0f-1f） toAlpha=目标透明度（0f-1f） */
fun getAlphaAnimationAnimationAnimationAnimationSelf( fromAlpha:Float,  toAlpha:Float) = AlphaAnimation(fromAlpha,toAlpha)








